from flask import Flask
import config
from ext import db
from models import User,Article,Tag
from articleviews import article_bp


app = Flask(__name__)
app.config.from_object(config) # 加载配置文件
db.init_app(app) #将app 跟db绑定
app.register_blueprint(article_bp) #注册蓝本

@app.route('/')
def hello_world():
    user = User(username='jiangjie',email="kangbazi@gmail.com")
    article = Article(title="Python从入门到放弃",content='mysql从删库到跑路')
    article.author = user
    tag1 = Tag(name="我儿子必须是高富帅")
    tag2 = Tag(name="屌丝和高富帅")
    article.tags.append(tag1)
    article.tags.append(tag2)
    db.session.add(article)
    db.session.commit()
    return 'hello world'

if __name__ == "__main__":
    app.run()